//
//  PlanFirstReusableView.m
//  SportSocial
//
//  Created by yull on 15/2/3.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "PlanFirstReusableView.h"

@implementation PlanFirstReusableView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        CGRect rect = CGRectMake(20, 0, 36, self.height);
        UILabel *label = [[UILabel alloc] initWithFrame:rect];
        label.textColor = [UIColor blackColor];
        label.font = [UIFont systemFontOfSize:18.0f];
        label.backgroundColor = [UIColor clearColor];
        label.numberOfLines = 2;
        label.text = @"今日计划";
        [self addSubview:label];
        
        rect = CGRectMake(label.right + 10, 15, self.width - label.right - 10 - label.left, 20);
        self.backView = [[UIView alloc] initWithFrame:rect];
        self.backView.backgroundColor = RGB(232, 228, 196);
        self.backView.layer.cornerRadius = 10;
        self.backView.layer.masksToBounds = YES;
        [self addSubview:self.backView];
        
        self.progressView = [[UIView alloc] initWithFrame:self.backView.bounds];
        self.progressView.backgroundColor = RGB(236, 111, 21);
        self.progressView.layer.cornerRadius = 10;
        self.progressView.layer.masksToBounds = YES;
        [self.backView addSubview:self.progressView];
        
        self.progressLabel = [[UILabel alloc] initWithFrame:self.backView.bounds];
        self.progressLabel.backgroundColor = [UIColor clearColor];
        self.progressLabel.textColor = self.progressView.backgroundColor;
        self.progressLabel.font = [UIFont systemFontOfSize:self.progressLabel.height - 4];
        [self.backView addSubview:self.progressLabel];
    }
    return self;
}

- (void)drawCellWithProgress:(NSInteger)progress
{
    self.progressView.width = self.backView.width * progress/100;
    
    if (progress == 100) {
        self.progressLabel.hidden = YES;
    }else {
        self.progressLabel.hidden = NO;
        self.progressLabel.text = [[NSString alloc] initWithFormat:@"%d%%",progress];
        
        self.progressLabel.left = self.progressView.right + 5;
    }
}
@end
